package cn.tedu.mall.front.service.impl;

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.front.service.IFrontProductService;
import cn.tedu.mall.pojo.product.vo.*;
import cn.tedu.mall.product.service.front.IForFrontAttributeService;
import cn.tedu.mall.product.service.front.IForFrontSkuService;
import cn.tedu.mall.product.service.front.IForFrontSpuService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FrontProductServiceImpl implements IFrontProductService {

    @DubboReference
    private IForFrontSpuService dubboSpuService;

    @DubboReference
    private IForFrontSkuService dubboSkuService;

    @DubboReference
    private IForFrontAttributeService dubboAttributeService;

    @Override
    public JsonPage<SpuListItemVO> listSpuByCategoryId(Long categoryId, Integer page, Integer pageSize) {
        //调用product模块编写好的业务逻辑层方法查询结果
        JsonPage<SpuListItemVO> spuListItemVOJsonPage = dubboSpuService.listSpuByCategoryId(categoryId,page,pageSize);
        return spuListItemVOJsonPage;
    }

    //根据spu_id查询spu对象
    @Override
    public SpuStandardVO getFrontSpuById(Long id) {
        //调用根据id查询spu的product方法
        SpuStandardVO spuStandardVO = dubboSpuService.getSpuById(id);
        return spuStandardVO;
    }

    //根据spu_id查询当前sku列表
    @Override
    public List<SkuStandardVO> getFrontSkusBySpuId(Long spuId) {
        List<SkuStandardVO> list = dubboSkuService.getSkusBySpuId(spuId);
        return list;
    }

    //根据spu_id查询spu详情
    @Override
    public SpuDetailStandardVO getSpuDetail(Long spuId) {
        SpuDetailStandardVO spuDetailStandardVO = dubboSpuService.getSpuDetailById(spuId);
        return spuDetailStandardVO;
    }

    //根据spuId查询所有参数类型的方法
    @Override
    public List<AttributeStandardVO> getSpuAttributesBySpuId(Long spuId) {
        //dubbo调用product模块提供的根据spuId查询所有参数类型详情的方法(有一个比较复杂的spl语句)
        //要知道这个SQL语句中表之间的关系
        List<AttributeStandardVO> list = dubboAttributeService.getSpuAttributesBySpuId(spuId);
        return list;
    }
}
